<?php /* Smarty version Smarty-3.1.16, created on 2016-03-04 09:15:47
         compiled from "E:\workspacePhp\phpb2cdemo\manage\page\systemmanage\systemrolemanage\roleManage.html" */ ?>
<?php /*%%SmartyHeaderCode:2620756ce7802cfd266-05960930%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    '697dbe8bda293349fd122c028769c7a4159e2375' => 
    array (
      0 => 'E:\\workspacePhp\\phpb2cdemo\\manage\\page\\systemmanage\\systemrolemanage\\roleManage.html',
      1 => 1457082939,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '2620756ce7802cfd266-05960930',
  'function' => 
  array (
  ),
  'version' => 'Smarty-3.1.16',
  'unifunc' => 'content_56ce7802d9a615_11154546',
  'variables' => 
  array (
    'charset' => 0,
  ),
  'has_nocache_code' => false,
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_56ce7802d9a615_11154546')) {function content_56ce7802d9a615_11154546($_smarty_tpl) {?><!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_smarty_tpl->tpl_vars['charset']->value;?>
" />
        <title>角色管理</title>
        <?php echo getCommon('');?>
 
		<?php echo getPlugSingle('easyui');?>

		<?php echo getPlugSingle('ztree');?>

	</head>
    <body>
    	<div id="setJuris" class="easyui-dialog" title="设置角色权限" closed="true" style="width:300px;height:400px;padding:10px"
    	data-options="
				iconCls: 'icon-edit',
				buttons: [{
					text:'保存',
					iconCls:'icon-ok',
					handler:function(){
						var treeObj = $.fn.zTree.getZTreeObj('jurisTree');
						var nodes = treeObj.transformToArray(treeObj.getNodes());
						//把选中数据传入后台保存起
						var selectedNodes = '';
						for (var i = 0; i < nodes.length; i++) {
							var checked = nodes[i].checked;
							if(checked)
								selectedNodes+=nodes[i].id+',';
						} 
						$.post('addRoleMenus',{
							'roleMenuIds':selectedNodes,
							'roleId':$('#setJuris input[name=roleId]').val()
						},function(data){
							eval('var dataJson='+data);
							if(dataJson.result==true){
								$.messager.show({
									title : '提示',
									msg :'您已成功添加该角色的权限！'
								});
								$('#setJuris').dialog('close');
								$('#roleTable').datagrid();
							}else{
								$.messager.show({
									title : '提示',
									msg :'修改失败，请重试！'
								});
							}
						});
					}
				},{
					text:'取消',
					handler:function(){
						$('#setJuris').dialog('close');
					}
				}],
				onResize:function(){
					$(this).dialog('center');
				}
			">
			<input name="roleId" type="hidden"/>
			<form id="jurisTree" class="ztree">
		    </form>
		</div>
    	<div id="editRole" class="easyui-dialog" title="编辑角色" closed="true" style="width:300px;height:200px;padding:10px"
    	data-options="
				iconCls: 'icon-edit',
				buttons: [{
					text:'确认',
					iconCls:'icon-ok',
					handler:function(){
						$('#editRoleForm').form('submit', {
							url : 'updateRoleInfo',
							onSubmit : function() {
								return $(this).form('validate');//对数据进行格式化
							},
							success : function(data) {
								eval('var dataJson='+data);
								if(dataJson.result==true){
									$.messager.show({
										title : '提示',
										msg :'您已成功修改角色'
									});
									$('#editRole').dialog('close');
									$('#roleTable').datagrid();
								}else{
									$.messager.show({
										title : '提示',
										msg :'修改失败，请重试！'
									});
								}
							}
						}); 
					}
				},{
					text:'取消',
					handler:function(){
						$('#editRole').dialog('close');
					}
				}],
				onResize:function(){
					$(this).dialog('center');
				}
			">
			<form id="editRoleForm" method="post">
		    	<table cellpadding="5">
		    		<tr>
		    			<td>角色名称:</td>
		    			<td><input name="roleId" type="hidden"/><input class="easyui-textbox" type="text" name="roleName" data-options="prompt:'请输入3到10个字内',required:true,validType:'length[3,10]'"></input></td>
		    		</tr>
		    		<tr>
		    			<td>角色描述:</td>
		    			<td><input id="password" class="easyui-textbox" type="text" name="roleDesc"></input></td>
		    		</tr>
		    		<tr>
		    			<td>角色排序:</td>
		    			<td><input id="repassword" class="easyui-textbox" type="text" name="roleOrder"></input></td>
		    		</tr>
		    	</table>
		    </form>
		</div>
    	<div id="addRole" class="easyui-dialog" title="添加新角色" closed="true" style="width:300px;height:200px;padding:10px"
    	data-options="
				iconCls: 'icon-add',
				buttons: [{
					text:'确认',
					iconCls:'icon-ok',
					handler:function(){
						$('#addRoleForm').form('submit', {
							url : 'insertRole',
							onSubmit : function() {
								return $(this).form('validate');//对数据进行格式化
							},
							success : function(data) {
								eval('var dataJson='+data);
								if(dataJson.result==true){
									$.messager.show({
										title : '提示',
										msg :'您已成功创建角色'
									});
									$('#addRole').dialog('close');
									$('#roleTable').datagrid();
								}else{
									$.messager.show({
										title : '提示',
										msg :'创建失败请重试！'
									});
								}
							}
						}); 
					}
				},{
					text:'取消',
					handler:function(){
						$('#addRole').dialog('close');
					}
				}],
				onResize:function(){
					$(this).dialog('center');
				}
			">
			<form id="addRoleForm" method="post">
		    	<table cellpadding="5">
		    		<tr>
		    			<td>角色名称:</td>
		    			<td><input class="easyui-textbox" type="text" name="roleName" data-options="prompt:'请输入3到10个字内',required:true,validType:'length[3,10]'"></input></td>
		    		</tr>
		    		<tr>
		    			<td>角色描述:</td>
		    			<td><input id="password" class="easyui-textbox" type="text" name="roleDesc"></input></td>
		    		</tr>
		    		<tr>
		    			<td>角色排序:</td>
		    			<td><input id="repassword" class="easyui-textbox" type="text" name="roleOrder"></input></td>
		    		</tr>
		    	</table>
		    </form>
		</div>
        <table id="roleTable" title="角色管理" style="width:100%;"
				data-options="collapsible:true,rownumbers:true,singleSelect:true,pagination:true,url:'queryRoleInfos',method:'post',toolbar:'#roleTableTool',multiSort:false">
			<thead>
				<tr>
					<th data-options="field:'roleName',resizable:false" width="10%">角色名称</th>
					<th data-options="field:'roleDesc',resizable:false" width="10%">角色描述</th>
					<th data-options="field:'roleCreatetime',align:'left',resizable:false,sortable:true" width="10%">创建时间</th>
					<th data-options="field:'roleOrder',align:'left',resizable:false" width="10%">排序号</th>
					<th data-options="field:'userLoginId',resizable:false" width="10%">创建用户</th>
					<th data-options="field:'menuStrs',resizable:false,formatter:nullFix" width="29%">当前权限</th>
					<th data-options="field:'roleIsUsed',align:'left',formatter:formatState,resizable:false" width="10%">是否可用</th>
					<th data-options="field:'_op',align:'left',formatter:rowOp" width="10%">操作</th>
				</tr>
			</thead>
		</table>
		<div id="roleTableTool" style="padding:5px;height:auto">
			<div style="margin-bottom:5px">
				<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addRole();">添加角色</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="javascript:window.location.reload()">刷新</a>
			</div>
			<div>
				<form id="queryTableInfo" method="post">
					角色名称: <input class="easyui-textbox" name="roleName" style="width:80px">
					创建时间: <input class="easyui-datebox" name="createtimeStart" style="width:80px">
					到: <input class="easyui-datebox" name="createtimeEnd" style="width:80px">
					是否有效: 
					<select class="easyui-combobox" name="roleIsUsed" panelHeight="auto" style="width:100px">
						<option value="3">所有</option>
						<option value="1">有效</option>
						<option value="2">无效</option>
					</select>
					<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="queryTableInfo()">搜索</a>
					<a href="#" class="easyui-linkbutton" iconCls="icon-redo" onclick="clearRoleForm()">清空条件</a>
				</form>
			</div>
		</div>
		<script type="text/javascript">
			//状态解释器
			function formatState(val,row){
				switch(val){
					case '1':
						return '<span style="color:green;">可用</span>';
						break;
					case '2':
						return '<span style="color:#333333;">无效</span>';
						break;
					default:
						return '<span style="color:#333333;">-</span>';
						break;
				}
			}
			
			//添加新用户
			function addRole(){
				//每次打开前都要清除先前填写的信息
				$('#addRoleForm').form('clear');
				$('#addRole').dialog('open');
			}
			
			//对每行的操作自定义
			function rowOp(val,row){
				var html = '';
				//角色设置权限
				html += '<a href="#" onclick="setAuthorityForRole('+row.roleId+')">设置权限</a>';
				html += '<a href="#" onclick="loadRoleInfo('+row.roleId+')">编辑</a>';
				//如果是启动的就开启锁定按钮和封号按钮
				if(row.roleIsUsed == 1){
					html += '<a href="#" onclick="shieldRoleInfo('+row.roleId+')">屏蔽</a>';
				}else  
					html += '<a href="#" onclick="enableRoleInfo('+row.roleId+')">启用</a>';
				return html;
			}
			
			//带条件查询信息
			function queryTableInfo(){
				$("#roleTable").datagrid("load", {
					roleName:$('#queryTableInfo input[name="roleName"]').val(),
					createtimeStart:$('#queryTableInfo input[name="createtimeStart"]').val(),
					createtimeEnd:$('#queryTableInfo input[name="createtimeEnd"]').val(),
					roleIsUsed:$('#queryTableInfo input[name="roleIsUsed"]').val()
		        });
			}
			
			//清空条件
			function clearRoleForm(){
				$('#queryTableInfo').form('clear');
			}
			
			
			//如果为空就显示-
			function nullFix(val,row){
				if(val==null || val=='')return '-';
				else return val;
			}
			
			//对编辑信息默认加载原有的信息再进行修改
			function loadRoleInfo(roleId){
				$('#editRole').dialog('open');
				//先清空后加载
				$('#editRoleForm').form('clear');
				
				$.post('queryRoleInfo', { 'roleId':roleId } ,function(data){
					eval('var dataJson = '+data);
					$('#editRoleForm').form('load', dataJson.roleInfo[0]);
				});
			}
			
			//屏蔽一个角色
			function shieldRoleInfo(roleId){
				$.messager.confirm('提醒', '你是否确认要屏蔽该角色?', function(r){
					if(r){
						$.post('updateRoleStateInfo', { 'roleId':roleId,'roleIsUsed':2} ,function(data){
							eval('var dataJson = '+data);
							if(dataJson.result==true){
								$.messager.show({
									title : '提示',
									msg :'您已成功屏蔽该角色!'
								});
								$('#roleTable').datagrid();
							}else{
								$.messager.show({
									title : '提示',
									msg :'操作失败，请重试!'
								});
							}
						});
					}
				});
			}
			
			//启动一个角色
			function enableRoleInfo(roleId){
				$.messager.confirm('提醒', '你是否确认要启动该角色?', function(r){
					if(r){
						$.post('updateRoleStateInfo', { 'roleId':roleId,'roleIsUsed':1} ,function(data){
							eval('var dataJson = '+data);
							if(dataJson.result==true){
								$.messager.show({
									title : '提示',
									msg :'您已成功启动该角色!'
								});
								$('#roleTable').datagrid();
							}else{
								$.messager.show({
									title : '提示',
									msg :'操作失败，请重试!'
								});
							}
						});
					}
				});
			}
			
			//每次在设置权限的时候弹出权限弹出框并赋予权限信息
			function setAuthorityForRole(roleId){
				//打开权限设置弹出框
				$('#setJuris').dialog('open');
				//每次打开要把roleId传入角色菜单弹出框信息里面去
				$('#setJuris input[name="roleId"]').val(roleId);
				var setting = {
					check: {
						enable: true
					},
					data: {
						simpleData: {
							enable: true
						}
					}
				};
				$.post('queryMenusByRoleId',{'roleId':roleId},function(data){
					eval('var dataJson = '+data);
					zNodes = dataJson.roleMenus;
					
					zTreeNode = $.fn.zTree.init($("#jurisTree"), setting, zNodes);
					zTreeNode.expandAll(true);
					var zTree = $.fn.zTree.getZTreeObj("jurisTree");
					zTree.setting.check.chkboxType = { "Y":"ps", "N":"ps"};
				});
			}
			
		
			$(function(){
				var pager = $('#roleTable').datagrid({
					method: 'POST',
					loadMsg: '数据加载中,请稍候...',
					pagination: true,   
					pageSize: 15,//每页显示的记录条数，默认为10 
					pageList: [15, 30, 45]//可以设置每页记录条数的列表  
				}).datagrid('getPager');	// get the pager of datagrid
				pager.pagination(/* {
					buttons:[{
						iconCls:'icon-add',
						title:'添加角色',
						handler:function(){
							
						}
					}]
				} */
					{ pageSize: 15,//每页显示的记录条数，默认为20
			        pageList: [15,30,45] }//可以设置每页记录条数的列表 
				);			
			})
		</script>
    </body>
</html>
<?php }} ?>
